$(document).ready(function(){
	
	$( function($){
		var quiz = [
	        {
	                ques: "Quelle est la couleur du cheval blanc d'Enri IV ?", //question
	                ans: "Gris par la poussière.", // Correct answer
	                ansSel : "Bleu ?", // Wrong answer
	                ansInfo : "Pour info, on a jamais vraiment sut, ça dépendait du temps..."  // answer information.
	        },
	        {
	                ques: "En quelle anné Steeve Jobs est il mort ?", 
	                ans: "2011",
	                ansSel: "Tonton Steeve est immortel !", 
	                ansInfo : "Gold-Au <br/>More info <a href='http://www.periodictable.com/Elements/079/index.html'>here</a>"
	        }
		];
		var lang = {
                ans:{   // _lang.ans are shown during the display of .q-result, the answer result.
                        corrAns: "La bonne réponse était :",
                        praise: 'Bien joué !',
                        whyAns: "Infos:",
                        yourAns: "Votre réponse :"
                },
                btn:{   // [ "text", "title" ]
                        begin: [ "Que le quizz commence !" ],
                        check: [ "Valider" ],
                        del: [ "Quitter", "Quitter le quiz" ],
                        help: [ "Aide", 'Besoin d\'aide ?'],
                        next: [ "Suivant" ],
                        restart: [ "Recommencer", "Quitter et recommencer le quiz" ],
                        details: [ "Statistiques" ],
                        review: [ "Détails des réponses" ],
                        showOnlyMissed: [ "", "Click to show only missed questions." ],
                        quit: [ "Quitter", "Quitter le quiz" ],
                        quitNo: [ "Revenir", "Back" ],
                        quitYes: [ 'Quitter', "Yes" ]
                },
                err:{
                        badQType: "Quiz non-valide",
                        badKey: "Clé non-valide",
                        error: "Erreur", 
                        noQType: "Aucun type de quizz selectonné",
                        noQues: "Ce quizz n'a pas de question",
                        notArr: "Doit être un tableau",
                        notObj: "Doit être un objet"
                },
                stats:{
                        right: "Réponses correct",
                        rate: "Pourcentage de réussite",
                        score: "Votre score",
                        wrong: "Réponses incorrect",
                        total: "Total",
                        tried: "Essais"
                },
                quiz:{
                        tfFalse: "Faux",
                        tfTrue: "Vrai"
                }
        }
		$( "#quiz-area" ).jQuizMe( quiz, { quizType: "multiList" }, lang );
	});
		
	// Init countdown
	/*
		Class:    	countDown
		Author:   	David Walsh
		Website:    http://davidwalsh.name
		Version:  	1.0.0
		Date:     	11/30/2008
		Built For:  jQuery 1.2.6
	*/
	
	jQuery.fn.countDown = function(settings,to) {
		settings = jQuery.extend({
			startFontSize: '22px',
			endFontSize: '22px',
			duration: 1000,
			startNumber: 30,
			endNumber: 0,
			callBack: function() { }
		}, settings);
		return this.each(function() {
			
			//where do we start?
			if(!to && to != settings.endNumber) { to = settings.startNumber; }
			
			//set the countdown to the starting number
			$(this).text(to).css('fontSize',settings.startFontSize);
			
			//loopage
			$(this).animate({
				'fontSize': settings.endFontSize
			},settings.duration,'',function() {
				if(to > settings.endNumber + 1) {
					$(this).css('fontSize',settings.startFontSize).text(to - 1).countDown(settings,to - 1);
				}
				else
				{
					settings.callBack(this);
				}
			});
					
		});
	};
	
	$('.time').countDown({
		startNumber: 30,
		callBack: function(gameOver) {
			$('.looser-popin').fancybox({
				overlayOpacity : '0.8',
				overlayColor : '#000',
				titleShow : false,
				showCloseButton : false,
				enableEscapeButton : false,
				scrolling : 'no'
			}).trigger('click');
		}
	});
});